﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.UI.MobileControls;
using System.Collections.Generic;

namespace HZ.DrugTrade.Web.Admin.RelationQuery
{
    public partial class checkPSAreaByZbzx : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
        public void BindData()
        {
            if (Request.QueryString["psid"] != "" && Request.QueryString["psid"] != null)
            {
                string comPS_Ids = " and companyps_id = '" + Request.QueryString["psid"].ToString() + "'";
               string comPS_Id = Request.QueryString["psid"].ToString();
                DataTable dtArea = HZ.DrugTrade.BLLFactory.Factory.BLL_Company().GetAreasById(comPS_Ids);
                this.GridView1.DataSource = dtArea;
                this.GridView1.DataBind();
                this.lblSort.Text = HZ.DrugTrade.BLLFactory.Factory.BLL_Company().GetCompanyType(comPS_Id);
                HZ.DrugTrade.Model.CompanyInfo com = HZ.DrugTrade.BLLFactory.Factory.BLL_Company().GetCompanyInfoByID(comPS_Id);
                this.lblComName.Text = com.CompanyName;
                this.lblUserCode.Text = comPS_Id;//企业用户编号
                txtOtherReason.Text = "";
                //txtOtherReason.Text = HZ.Data.DbHelperFactory.Create().ExecuteScalar("select reasonByZbzx from TB_PSselectArea where companyPS_Id='" + comPS_Id + "'").ToString();
                
            }
            else
            {
                this.Controls.Add(new LiteralControl("<script>alert('参数错误')</script>"));
                Response.Redirect("../UserLogin.aspx");
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        protected string getCheckstatus(string str)
        {
            if (str == "1")
            {
                return "<label style='color:green;'>已通过</label>";
            }
            if (str == "2")
            {
                return "<label style='color:red;'>未通过</label>";
            }
            if (str == "0")
            {
                return "未审核";
            }
            return "";
        }

        //审核通过
        protected void btnPass_Click(object sender, EventArgs e)
        {
            //获取选择区域的ID
            string areaIDs = Request["checkbox1"];
            if (areaIDs=="")//若没有选择要审核的区域
            {
                this.Controls.Add(new LiteralControl("<script>alert('请选择区域');</script>"));
                return;
            }
            
            HZ.DrugTrade.Model.PSSelectArea ps=new HZ.DrugTrade.Model.PSSelectArea ();
            ps.CompanyPS_Id=this.lblUserCode.Text;
            bool flag = HZ.DrugTrade.BLLFactory.Factory.BLL_Company().CheckAreaByZbzx(ps, CurrentAccount.GetUser().UserID, areaIDs, 1);
            if (flag)
            {
                //HZ.Web.MessageBox.Show("审核成功");
                this.Controls.Add(new LiteralControl("<script>alert('审核成功')</script>"));
                BindData();
            }
            else
            {
                HZ.Web.MessageBox.Show("审核失败");
            }
        }
        //审核未通过
        protected void btnUnPass_Click(object sender, EventArgs e)
        {
            //获取选择区域的ID
            string areaIDs = Request["checkbox1"];
            if (areaIDs == ""||areaIDs==null)//若没有选择要审核的区域
            {
                this.Controls.Add(new LiteralControl("<script>alert('请选择区域');</script>"));
                return;
            }
            if (this.txtOtherReason.Text.Trim()=="")
            {
                this.Controls.Add(new LiteralControl("<script>alert('请填写审核不通过原因');</script>"));
                return;
            }
            
            HZ.DrugTrade.Model.PSSelectArea ps = new HZ.DrugTrade.Model.PSSelectArea();
            ps.CompanyPS_Id = this.lblUserCode.Text;
            ps.ReasonByZbzx = this.txtOtherReason.Text;
            bool flag = HZ.DrugTrade.BLLFactory.Factory.BLL_Company().CheckAreaByZbzx(ps, CurrentAccount.GetUser().UserID, areaIDs, 0);
            if (flag)
            {
                //HZ.Web.MessageBox.Show("审核成功");
                this.Controls.Add(new LiteralControl("<script>alert('审核成功')</script>"));
                BindData();
            }
            else
            {
                HZ.Web.MessageBox.Show("审核失败");
            }
        }

        protected void chkAll_CheckedChanged(object sender, EventArgs e)
        {
            //if (cbkList.Items.Count > 0)
            //{
            //    if (chkAll.Checked == true)
            //    {
            //        for (int i = 0; i < cbkList.Items.Count; i++)
            //        {
            //            cbkList.Items[i].Selected = true;
            //        }

            //    }
            //    else
            //    {
            //        for (int i = 0; i < cbkList.Items.Count; i++)
            //        {
            //            cbkList.Items[i].Selected = false;
            //        }
            //    }
            //}
            
        }
        
        /// <summary>
        /// 是否选择了区域
        /// </summary>
        /// <returns></returns>
        public bool IsCheck()
        {
            bool flag = false;
            //if (cbkList.Items.Count>0)
            //{
            //    for (int i = 0; i < cbkList.Items.Count; i++)
            //    {
            //        if (cbkList.Items[i].Selected==true)
            //        {
            //            flag = true;
            //            break;
            //        }
            //        continue;
            //    }
            //}
            return flag;
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("RelationCheckArea.aspx");
        }
    }
}
